/*
 * CaseHistory.java
 *
 * Created on August 31, 2008, 1:38 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Project.bussiness;

import Project.DBHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;


public class CaseHistory {
    
    /** Creates a new instance of CaseHistory */
    private int CaseID;
    private int PatientID;
    private String CaseHistory;
    private String AdmissionDate;
    private String DischargeDate;

    public int getCaseID() {
        return CaseID;
    }

    public void setCaseID(int CaseID) {
        this.CaseID = CaseID;
    }

    public int getPatientID() {
        return PatientID;
    }

    public void setPatientID(int PatientID) {
        this.PatientID = PatientID;
    }

    public String getCaseHistory() {
        return CaseHistory;
    }

    public void setCaseHistory(String CaseHistory) {
        this.CaseHistory = CaseHistory;
    }

    public String getAdmissionDate() {
        return AdmissionDate;
    }

    public void setAdmissionDate(String AdmissionDate) {
        this.AdmissionDate = AdmissionDate;
    }

    public String getDischargeDate() {
        return DischargeDate;
    }

    public void setDischargeDate(String DischargeDate) {
        this.DischargeDate = DischargeDate;
    }
    
    public static Vector getAllCaseHistory() throws SQLException
    {
        Vector v = new Vector();
        try {
        ResultSet rs = DBHelper.executeQuery("spGetAllCaseHistory");
            while(rs.next()){
                CaseHistory c = new CaseHistory();
                c.setCaseID(rs.getInt(1));
                c.setPatientID(rs.getInt(2));
                c.setCaseHistory(rs.getString(3));
                c.setAdmissionDate(rs.getString(4));
                c.setDischargeDate(rs.getString(5));
                v.add(c);
            }
        } catch(SQLException sqle) {
            throw sqle;
        }
        return v;        
    }   
    
    public static Vector getCaseHistoryByPatientId(int id) throws SQLException
    {
        Vector v = new Vector();        
        try {
            // Create param list
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            ResultSet rs = DBHelper.executeQuery("spSearchCaseHistoryByPatientID", paramList);
            
            while(rs.next()){
                CaseHistory c = new CaseHistory();
                c.setCaseID(rs.getInt(1));
                c.setPatientID(rs.getInt(2));
                c.setCaseHistory(rs.getString(3));
                c.setAdmissionDate(rs.getString(4));
                c.setDischargeDate(rs.getString(5));
                v.add(c);
            }
        } catch(SQLException sqle) {
            // Handle exception            
            throw sqle;
        }   
        return v;
    }     
    
    public static int insertCaseHistory(CaseHistory c) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(c.PatientID);
            paramList.add(c.CaseHistory);
            paramList.add(c.AdmissionDate);           
            i=DBHelper.executeUpdate("spInsertCaseHistory",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }      
    public static int UpdateCaseHistory(int id, CaseHistory c) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            paramList.add(new Integer(c.CaseID));
            paramList.add(c.CaseHistory);
            paramList.add(c.AdmissionDate);           
            paramList.add(c.DischargeDate);
            i=DBHelper.executeUpdate("spUpdateCaseHistory",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }   
    public static int updateDischangeDate(int id, String date) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));        
            paramList.add(date);
            i=DBHelper.executeUpdate("spUpdateDischangeDate",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }     
    public static int DeleteCaseHistory(int id) throws SQLException
    {
        int i;
        try{
            Vector paramList = new Vector();
            paramList.add(new Integer(id));
            i=DBHelper.executeUpdate("spDeleteCaseHistory",paramList);
        } catch(SQLException e)
        {
            throw e;
        }
        return i;
    }
    public static int getCaseIDtop()
    {
        int id=0;
        try {
        ResultSet rs = DBHelper.executeQuery("getCaseID");
            while(rs.next()){
                id=rs.getInt(1);
            }
        } catch(SQLException sqle) {
            sqle.printStackTrace();
        }
        return id;
    }
}
